-
-
Notifications
You must be signed in to change notification settings - Fork 74
use LazyBufferCache instead of FixedSizeDiffCache #1191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This shouldn't be needed now? |
Yeah, I'll close it |
@ChrisRackauckas this fixes the Core2 tests. |
But there's a lot of other broken tests it creates? |
4988fe1
to
a55f1de
Compare
I don't see any here that aren't also broken on master? |
What's the performance change from this? |
And which tests does this fix? |
This just fixes the Core 2 tests on Julia 1.11. As for performance I'll set a benchmark to see. |
I ran this: using Zygote, SciMLSensitivity
using OrdinaryDiffEq, ForwardDiff, Test
using BenchmarkTools
p = rand(3)
function dudt(u, p, t)
u .* p
end
function loss(p, sensealg)
prob = ODEProblem(dudt, [3.0, 2.0, 1.0], (0.0, 10.0), p)
sol = solve(prob, ImplicitEuler(), dt=0.01, saveat=0.1, sensealg=sensealg,
abstol=1e-5, reltol=1e-5)
sum(abs2, Array(sol))
end
@btime Zygote.gradient(
p -> loss(p, QuadratureAdjoint(autojacvec=EnzymeVJP())), p)
function lv(du, u, p, t)
du[1] = p[1] * u[1] - p[2] * u[1] * u[2]
du[2] = -3 * u[2] + u[1] * u[2]
end
function loss_lv(p,sensealg)
prob_lv = ODEProblem(lv, [1.0, 2.0], (0.0, 10.0), p)
sol = solve(prob_lv, ImplicitEuler(), dt=0.01, saveat=0.1, sensealg=sensealg,
abstol=1e-5, reltol=1e-5)
sum(abs2, Array(sol))
end
@btime Zygote.gradient(
p -> loss_lv(p, QuadratureAdjoint(autojacvec=EnzymeVJP())), [1.0, 2.0])
function vanderpol(du, u, p, t)
du[1] = u[2]
du[2] = p[1]*((1-u[1]^2)*u[2] - u[1])
end
function loss_vp(p, sensealg)
prob_vp = ODEProblem(vanderpol, [1.0, 2.0], (0.0, 10.0), p)
sol = solve(prob_vp, Rodas5(), dt=0.01, saveat=0.1, sensealg=sensealg,
abstol=1e-5, reltol=1e-5)
sum(abs2, Array(sol))
end
@btime Zygote.gradient(
p -> loss_vp(p, QuadratureAdjoint(autojacvec=EnzymeVJP())), [20.0]) With FixedSizeDiffCache and LazyBufferCache on Julia 1.10. |
Open an issue about this performance regression. It's minor enough to not be a major worry, but we should track it because if Enzyme fixes their part then we should prefer DiffCache. |
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
This makes EnzymeVJP use LazyBufferCache instead of FixedSizeDiffCache to avoid problems with
reinterpret
and Enzyme.